<template>
	<view>
		<u-navbar :title="title" :fixed="fixed" :bgColor="bgColor" :placeholder="placeholder"
		 :leftIcon="leftIcon" @leftClick="backPage" :leftIconColor="leftColor" :titleStyle ="{fontSize: '36rpx',fontWeight: 'bold'}" :is-back="isBack">
			<view slot="left" v-if="noLeft"></view>
		</u-navbar>
	</view>
</template>

<script>
	export default {
		name:"index",
		props: {
			title: {
				type: String,
				default: ""
			},
			placeholder: {
				type: Boolean,
				default: true
			},
			bgColor: {
				type: String,
				default: 'transparent'
			},
			fixed:{
				type: Boolean,
				default: true
			},
			leftColor: {
				type: String,
				default: '#303133'
			},
			noLeft: {
				type: Boolean,
				default: true
			},
			isBack: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				leftIcon: 'arrow-left',
				pageLength: 0
			};
		},
		mounted() {
			this.pageLength = getCurrentPages().length;
			console.log(this.pageLength);
			if(this.pageLength > 1) {
				this.leftIcon = 'arrow-left'
			}else {
				this.leftIcon = 'home'
			}
		},
		methods: {
			backPage() {
				console.log(this.pageLength);
				if(this.pageLength > 1){
					uni.navigateBack({delta:1})
				}else {
					uni.switchTab({
						url:"/pages/index/index",
						fail: (err) => {
							console.log(err);
						}
					})
				}
			}
		}
	}
</script>

<style>

</style>